<template>
    <div class="data-page">
        <div class="nav-back" @click="goBack">
            <i class="el-icon-arrow-left"></i>
        </div>
        <div class="search-wrap">
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item label="起始日期">
                    <el-date-picker v-model="value1" type="daterange"
                        range-separator="至"
                        format="yyyy-MM-DD"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
				<el-form-item>
                    <el-button class="btn bg-blue" @click="queryClick">查询</el-button>
                    <el-button class="btn" @click="resetClick">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="data-list">
           <div class="cont">
                <div class="title marg-B1 fs-16 fw-7">
                    时间：{{begin_date}}至{{end_date}}
                </div>
                <div class="flex">
                    <div class="pad-T2 pad-L2" style="width: 20%;">
                        <div class="inet-box t-center marg-B2">
                            <div class="fs-16" style="color: #2A82E4;">{{listData.clue_total}}</div>
                            <div class="t-eight fs-12">接单</div>
                        </div>
                        <div class="inet-box t-center">
                            <div class="fs-16" style="color: #FF8D1A;">{{listData.money_total}}</div>
                            <div class="t-eight fs-12">消耗积分</div>
                        </div>
                    </div>
                    <div style="flex: 1;" class="charts-box" ref="">
                        <div ref="chartRef1" style="width: 100%;height:500px;"></div>
                    </div>
                </div>
           </div>
		</div>
    </div>
</template>
<script>
import {request} from "@/assets/js/utils/request"
import *as echarts from 'echarts'
import mixin from '@/assets/js/mixin'
export default {
    mixins: [mixin],
    data() {
        return {
            value1: [],
            listData: [],
            yearData: [],
            dayData: [],
			timeList: [],
            begin_date: '',
            end_date: ''
        }
    },
    created() {
        
    },
    mounted() {
        if(this.$route.query.begin_date) {
            this.begin_date = this.$route.query.begin_date
            this.end_date = this.$route.query.end_date
        }
        this.timeData()
    },
    methods: {
        queryClick() {
            this.begin_date = this.formattedDate(this.value1[0])
            this.end_date = this.formattedDate(this.value1[1])
            this.timeData()
        },
        resetClick() {

        },
        dayCharts(data) {
            let myChart = echarts.init(this.$refs.chartRef1);
            myChart.setOption({
                legend: {
					icon: 'circle',
                    top: 'bottom'
                },
                label: {
                    formatter: '{d}%',
                },
                series: [
                    {
                        type: 'pie',
                        radius: [0, '60%'],
                        selectedMode: 'single',
						itemStyle: {
							normal: {
								color: function (colors) {
									var colorList = ["#7948EA","#FF8D1A","#FFC300","#43CF7C","#fc8251","#5470c6","#9A60B4",
									   "#ef6567",
									   "#f9c956",
									   "#3BA272"
									];
									return colorList[colors.dataIndex];
								}
							},
						},
                        data: data
                    }
                ]
            })
        },        
        timeData() {
            request({
                url: `/user/charts/range?begin_date=${this.begin_date}&end_date=${this.end_date}`,
                method: 'GET'
            }).then(res => {
                if(res.code == 200) {
                    this.listData = res.data || []
                    let catList = res.data.category_list || []
                    if(catList.length > 0) {
                        catList.forEach((item) => {
                            this.$set(item,'name',item.category_title)
                            this.$set(item,'value',item.total)
                        })
                        this.dayCharts(catList)
                    }
                }
            })
        }
    }
}
</script>
<style lang="less" scoped>
.data-page{
	.data-list{
        padding: 20px;
        background: #fff;
        .cont{
            width: 80%;
            margin: 0 auto;
            padding: 20px;
        }
		.title{
            // text-align: center;
            padding: 20px;
            line-height: 30px;
            color: #1F2E54;
            font-weight: 700;
            background: #E5E5E5;
        }
        .inet-box{
            width: 100%;
            // height: 66px;
            padding: 20px;
            margin: 10px;
			margin-bottom: 20px;
            text-align: center;
            line-height: 25px;
            border-radius: 6px;
            background: rgba(255, 255, 255, 1);
            border: 1px solid rgba(229, 229, 229, 1);
        }
        .charts-box{
            height: 200rpx;
        }
        .list-bar{
            .cire{
                width: 16rpx;
                height: 16rpx;
                border-radius: 50rpx;
            }
            .bg1{
                background: #7948EA;
            }
            .bg2{
                background: #FF8D1A;
            }
            .bg3{
                background: #FFC300;
            }
            .bg4{
                background: #43CF7C;
            }
        }
	}
}
/deep/.search-wrap{
    margin: 20px 0;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    background: #fff;
    .el-form-item{
        margin-bottom: 0;
    }
    .btn{
        padding: 0;
        width: 80px;
        height: 32px;
        border: none;
        // background: #016aed;
    }
    .bg-blue{
        color: #ffffff;
        background: #2967E3;
    }
    .el-select {
        width: 100%;
    }
    .el-input{
        width: 150px;
        .el-input__inner{
            height: 32px;
        }
    }
    .el-date-editor{
        width: 100%;
        .el-input{
            width: 100%;
        }
        .el-input__prefix{
            .el-input__icon{
                line-height: 32px;
            }
        }
        .el-input__suffix{
            .el-input__suffix-inner{
                .el-input-circle-close{
                    line-height: 32px;
                }
            }
        }
    }
}
</style>